/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.gwt.basics.controller;

import com.genia.toolbox.basics.bean.DataContainer;
import com.genia.toolbox.web.gwt.basics.bean.FileInformation;
import com.genia.toolbox.web.gwt.basics.context.GwtBasicsContext;
import com.genia.toolbox.web.gwt.basics.form.IdentifierForm;
import com.genia.toolbox.web.mvc.controller.AbstractDownloadController;

/**
 * {@link org.springframework.web.servlet.mvc.Controller} the allows to preview
 * uploaed files.
 */
public class GwtFileUploadPreviewController
    extends AbstractDownloadController<IdentifierForm>
{

  /**
   * the {@link GwtBasicsContext} to use.
   */
  private GwtBasicsContext context;



  /**
   * getter for the context property.
   * 
   * @return the context
   */
  public GwtBasicsContext getContext()
  {
    return context;
  }



  /**
   * setter for the context property.
   * 
   * @param context
   *          the context to set
   */
  public void setContext(GwtBasicsContext context)
  {
    this.context = context;
  }



  /**
   * returns the {@link DataContainer} to display. It does not need to make any
   * security check because the files informations are handled by the session of
   * the user, so if a user has a file information, he is authorized to access
   * the file.
   * 
   * @param identifierForm
   *          the form containing the parameter of the request
   * @return the {@link DataContainer} to display or <code>null</code> if no
   *         such object exists
   * @see com.genia.toolbox.web.mvc.controller.AbstractDownloadController#getDataContainer(java.lang.Object)
   */
  @Override
  public DataContainer getDataContainer(IdentifierForm identifierForm)
  {
    FileInformation fileInformation = getContext().getFileInformation(identifierForm.getIdentifier());
    if (fileInformation == null) {
      return null;
    }
    return fileInformation;
  }

}
